package com.qingcheng.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.qingcheng.entity.OrderOrderItems;
import com.qingcheng.entity.PageResult;
import com.qingcheng.service.order.OrderService;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/orderpay")
public class OrderPayController {


    @Reference
    private OrderService orderService;

    /**
     * 根据用户名查询用户订单信息
     *
     * @param page 开始页
     * @param size 分页大小
     * @return
     */
    @GetMapping("/findOrderPage")
    public PageResult<OrderOrderItems> findOrderPage(@RequestParam(required = false, defaultValue = "1") int page, int size) {

        String username = SecurityContextHolder.getContext().getAuthentication().getName();
        Map map = new HashMap<String, Object>();
        map.put("username", username);
        PageResult payPage = orderService.findPayPage(map, page, size);

        return payPage;
    }

    /**
     * 根据商品id查询订单详情
     * @param orderId
     * @return
     */
    @GetMapping("/findOneOrder")
    public OrderOrderItems findOneOrder(String orderId) {
        String username = SecurityContextHolder.getContext().getAuthentication().getName();
        OrderOrderItems orderOrderItems = orderService.findOneOrder(orderId,username);

        return orderOrderItems;

    }

}
